<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryInfoForm" v-show="showSearch" :inline="true" label-width="68px">
            <el-form-item label="处理状态" prop="status">
                <el-select
                        v-model="queryParams.disposeStatus"
                        placeholder="特征提取结果处理状态"
                        clearable
                        style="width: 200px"
                        @change="handleQueryInfo"
                >
                    <el-option
                            v-for="dict in sys_feature_info_status"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="调制方式" prop="modelType">
                <el-input
                    v-model="queryParams.modelType"
                    placeholder="请输入调制方式"
                    clearable
                    style="width: 120px"
                    @keyup.enter="handleQueryInfo"
                />
            </el-form-item>
            <el-form-item label="编码方式" prop="codeType">
                <el-input
                    v-model="queryParams.codeType"
                    placeholder="请输入编码方式"
                    clearable
                    style="width: 120px"
                    @keyup.enter="handleQueryInfo"
                />
            </el-form-item>
            <el-form-item label="创建时间" style="width: 308px">
                <el-date-picker
                        v-model="queryDateRange"
                        value-format="YYYY-MM-DD"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        @change="handleQueryInfo"
                ></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQueryInfo">搜索</el-button>
                <el-button icon="Refresh" @click="resetQueryInfo">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                        type="danger"
                        plain
                        icon="Delete"
                        :disabled="multiple"
                        @click="handleDeleteTask"
                >删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="warning"
                        plain
                        icon="Download"
                        @click="handleExport"
                        v-hasPermi="['system:role:export']"
                >导出</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getInfoList"></right-toolbar>
        </el-row>

        <!-- 表格数据 -->
        <el-table v-loading="loading" :data="featureInfoList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
                label="序号"
                type="index"
                width="50"
                align="center">
                <template #default="scope">
                    {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
                </template>
            </el-table-column>
<!--            <el-table-column label="结果编号" prop="cnId"/>-->
            <el-table-column label="载波编号" prop="carrierId"/>
            <el-table-column label="处理状态" prop="disposeStatus">
                <template #default="scope">
                    <dict-tag :options="sys_feature_info_status" :value="scope.row.disposeStatus" />
                </template>
            </el-table-column>
            <el-table-column label="载波频率" align="center" key="carrierFreq" prop="carrierFreq" :show-overflow-tooltip="true" />
            <el-table-column label="载波中频" align="center" key="carrierCenterFreq" prop="carrierCenterFreq" :show-overflow-tooltip="true" />
            <el-table-column label="载波带宽" align="center" key="carrierBand" prop="carrierBand" :show-overflow-tooltip="true" />
            <el-table-column label="载噪比" align="center" key="carrierSnr" prop="carrierSnr"/>
            <el-table-column label="传输方式" align="center" key="tranType" prop="tranType" />
            <el-table-column label="调制速率" align="center" key="modelRate" prop="modelRate" />
            <el-table-column label="调制方式" align="center" key="modelType" prop="modelType" />
            <el-table-column label="编码方式" align="center" key="codeType" prop="codeType" />
            <el-table-column label="编码码率" align="center" key="codeRate" prop="codeRate" />
            <el-table-column label="编码其他信息" align="center" key="codeOther" prop="codeOther" :show-overflow-tooltip="true"/>
            <el-table-column label="创建时间" align="center" prop="createTime">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-tooltip content="详细" placement="top" v-if="scope.row.roleId !== 1">
                        <el-button link type="primary" icon="View" @click="handleDetails(scope.row,true)" ></el-button>
                    </el-tooltip>
                    <el-tooltip content="修改" placement="top" v-if="scope.row.roleId !== 1">
                        <el-button link type="primary" icon="Edit" @click="handleDetails(scope.row,false)" ></el-button>
                    </el-tooltip>
                    <el-tooltip content="删除" placement="top" v-if="scope.row.disposeStatus == 2 || scope.row.disposeStatus == 3">
                        <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" ></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>

        <pagination
                v-show="featureInfoTotal > 0"
                :total="featureInfoTotal"
                v-model:page="queryParams.pageNum"
                v-model:limit="queryParams.pageSize"
                @pagination="getInfoList"
        />
    </div>

    <!-- 特征信息详情对话框 -->
    <el-dialog :title="detailsDialog.title" v-model="detailsDialog.open" append-to-body>
        <el-row :gutter="10" class="">
            <el-form ref="roleRef" :disabled="detailsDialog.disabled" :model="detailsDialog.featureInfo" :inline="true" :rules="detailsDialog.rules" label-width="100px">
                <el-form-item label="载波频率" prop="carrierFreq">
                    <el-input type="number" v-model="detailsDialog.featureInfo.carrierFreq" />
                </el-form-item>
                <el-form-item label="载波带宽" prop="carrierBand">
                    <el-input type="number" v-model="detailsDialog.featureInfo.carrierBand" />
                </el-form-item>
                <el-form-item label="载噪比" prop="carrierSnr">
                    <el-input type="number" v-model="detailsDialog.featureInfo.carrierSnr" />
                </el-form-item>
                <el-form-item label="传输方式" prop="tranType">
                    <el-input v-model="detailsDialog.featureInfo.tranType" />
                </el-form-item>
                <el-form-item label="调制速率" prop="modelRate">
                    <el-input type="number" v-model="detailsDialog.featureInfo.modelRate" />
                </el-form-item>
                <el-form-item label="调制方式" prop="modelType">
                    <el-input v-model="detailsDialog.featureInfo.modelType" />
                </el-form-item>
                <el-form-item label="编码方式" prop="codeType">
                    <el-input v-model="detailsDialog.featureInfo.codeType" />
                </el-form-item>
                <el-form-item label="编码码率" prop="codeRate">
                    <el-input v-model="detailsDialog.featureInfo.codeRate" />
                </el-form-item>
                <el-form-item style="width: 100%;" label="编码其他信息" prop="codeOther">
                    <el-input type="textarea" v-model="detailsDialog.featureInfo.codeOther" />
                </el-form-item>
                <el-form-item style="width: 100%;" label="备注" prop="remark">
                    <el-input type="textarea" v-model="detailsDialog.featureInfo.remark" />
                </el-form-item>
            </el-form>
        </el-row>
        <el-row :gutter="10" class="">
            <el-col  :sm="24" :lg="8" style="width: 250px;height: 250px;"><RateView ref="freqView"  :v-draw-data="detailsDialog.freqData"/></el-col>
            <el-col  :sm="24" :lg="8" style="width: 250px;height: 250px;"><RateView ref="rateView"  :v-draw-data="detailsDialog.rateData"/></el-col>
            <el-col  :sm="24" :lg="8" style="width: 250px;height: 250px;"><VectorView ref="freqView" :v-draw-data="detailsDialog.vectorData" /></el-col>
        </el-row>
        <el-row :gutter="10" class="">

        </el-row>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" :style="{ display: detailsDialog.visibleSubmitBtn} "  @click="detailsDialogSubmit">保存</el-button>
                <el-button @click="detailsDialogClose">关闭</el-button>
            </div>
        </template>
    </el-dialog>

</template>

<script>
import {
    delRadioFeatureInfo,
    listRadioFeatureInfo, updateRadioFeatureInfo
} from "@/api/signal/radioFeatureInfo";
import {getCurrentInstance} from "vue";
import {addDateRange, parseTime} from "@/utils/ruoyi";
import RateView from "@/components/rateView/index.vue";
import {readFileData} from "@/api/signal/fileData";
import {deleteRadioFeatureTask} from "@/api/signal/radioFeatureTask";

export default {
    name:'Featureinfo',
    components: {RateView},
    props: [],
    data() {
        return {
            featureInfoList:[],
            ids:[],
            multiple:true,//选中任务
            loading:false,
            featureInfoTotal:0,
            showSearch:true,
            queryDateRange: [],
            queryParams:{
                pageNum: 1,
                pageSize: 10,
                disposeStatus:"",
                modelType:"",
                codeType:""
            },
            detailsDialog:{
                title:'无线电特征信息详情',
                editable:false,
                open:false,
                featureInfo:{},
                freqData:[],
                rateData:[],
                vectorData:[],
                visibleSubmitBtn:'none',
            },
            rules: {

            },
            sys_feature_info_status:[],
        }
    },
    computed: {},
    watch: {},
    created() {
        let { sys_feature_info_status} = this.useDict("sys_feature_info_status");
        this.sys_feature_info_status = sys_feature_info_status
    },
    mounted() {
        this.handleQueryInfo()
    },
    methods: {
        parseTime,
        getInfoList(){
            this.loading = true
            listRadioFeatureInfo(addDateRange(this.queryParams, this.queryDateRange)).then(response => {
                this.featureInfoList = response.rows
                this.featureInfoTotal = response.total
                this.loading = false
            })
        },
        handleQueryInfo() {
            this.queryParams.pageNum = 1
            this.getInfoList()
        },
        resetQueryInfo() {
            this.queryDateRange = []
            this.$refs['queryInfoForm'].resetFields()
            this.queryParams.disposeStatus = ""
            this.handleQueryInfo()
        },
        handleDetails(row,disabled){
            this.detailsDialog.open = true;
            this.detailsDialog.disabled = disabled;//查看
            this.detailsDialog.visibleSubmitBtn = disabled ? 'none' : ''
            this.detailsDialog.featureInfo.carrierFreq = row.carrierFreq
            this.detailsDialog.featureInfo.carrierBand = row.carrierBand
            this.detailsDialog.featureInfo.carrierSnr= row.carrierSnr
            this.detailsDialog.featureInfo.tranType= row.tranType
            this.detailsDialog.featureInfo.modelRate= row.modelRate
            this.detailsDialog.featureInfo.modelType= row.modelType
            this.detailsDialog.featureInfo.codeType= row.codeType
            this.detailsDialog.featureInfo.codeRate= row.codeRate
            this.detailsDialog.featureInfo.codeOther= row.codeOther
            this.detailsDialog.featureInfo.remark= row.remark

            if(this.detailsDialog.featureInfo.cnId === row.cnId) {return}
            this.detailsDialog.featureInfo.cnId = row.cnId;
            //获取数据
            readFileData(row.freqData,0,0).then(response => {
                let c_data = new Int8Array(response)
                let f_data = new Float32Array(c_data.buffer)
                this.detailsDialog.freqData = f_data
            })
            readFileData(row.rateData,0,0).then(response => {
                let c_data = new Int8Array(response)
                let f_data = new Float32Array(c_data.buffer)
                this.detailsDialog.rateData = f_data
            })
            readFileData(row.vectorData,0,0).then(response => {
                let c_data = new Int8Array(response)
                let s_data = new Int16Array(c_data.buffer)
                this.detailsDialog.vectorData = s_data
            })
        },
        handleDelete(row){
            const that = this
            let idList = []
            idList.push(row.cnId);
            this.$modal.confirm('是否确认删除编号为"' + idList + '"的数据项？').then(function () {
                delRadioFeatureInfo(idList).then(response => {
                    that.$modal.msgSuccess(response.msg)
                    that.getTaskList()
                })
            }).catch(function () {

            })
        },
        detailsDialogSubmit(){
            const that = this
            updateRadioFeatureInfo(this.detailsDialog.featureInfo).then(response => {
                that.$modal.msgSuccess(response.msg)
                this.getInfoList()
            })
        },
        detailsDialogClose(){
            this.detailsDialog.open = false;
        }
    }
}
</script>

<style scoped>

</style>